package edu.udel.mboch.towerdefense;

import java.io.Serializable;

public class FloatingPosition implements Serializable
{
	private static final long serialVersionUID = 1234549266046692118L;
	private float x;
	private float y;
	
	public FloatingPosition(float x, float y)
	{
		this.x = x;
		this.y = y;
	}
	
	public float x()
	{
		return x;
	}
	
	public float y()
	{
		return y;
	}
	
	public void x(float x)
	{
		this.x = x;
	}
	
	public void y(float y)
	{
		this.y = y;
	}
	
	public float[] vectorTowards(Position p)
	{
		float[] vector = new float[2];
		if(p.x() > x)
			vector[0] = 1f;
		else if(p.x() < x)
			vector[0] = -1f;
		else
			vector[0] = 0f;
		if(p.y() > y)
			vector[1] = 1f;
		else if(p.y() < y)
			vector[1] = -1f;
		else
			vector[1] = 0f;
		return vector;
	}
	
	public float[] vectorTowards(FloatingPosition p)
	{
		float[] vector = new float[2];
		if(p.x() > x)
			vector[0] = 1f;
		else if(p.x() < x)
			vector[0] = -1f;
		else
			vector[0] = 0f;
		if(p.y() > y)
			vector[1] = 1f;
		else if(p.y() < y)
			vector[1] = -1f;
		else
			vector[1] = 0f;
		return vector;
	}
	
	public Position toPosition()
	{
		return new Position((int)x, (int)y);
	}
	
	public FloatingPosition copy()
	{
		return new FloatingPosition(x, y);
	}
	
	public String toString()
	{
		return x + " " + y;
	}
}
